home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / include / stdlib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-05  |  5.8 KB  |  203 lines

  1. /*
  2.  * stdlib.h --
  3.  *
  4.  *    Declares facilities exported by the "stdlib" portion of
  5.  *    the C library.
  6.  *
  7.  * Copyright 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /sprite/src/lib/include/RCS/stdlib.h,v 1.21 91/12/05 10:44:35 ouster Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _STDLIB
  20. #define _STDLIB
  21.  
  22. /* 
  23.  * sprite.h is needed for typedefs that are used in some function
  24.  * prototypes.  Unfortunately, some user programs define conflicting
  25.  * typedefs.  Because many programs probably include stdlib.h, we
  26.  * should give advance warning before forcing users to use the
  27.  * typedefs from sprite.h.  This must be done before we can turn on
  28.  * function prototypes for Sprite user programs.  (Or, change the 
  29.  * prototypes so that they don't use the Sprite typedefs.)
  30.  */
  31. #include <cfuncproto.h>
  32.  
  33. #ifdef KERNEL
  34. #include <sprite.h>
  35. #include <sys/types.h>
  36. #endif
  37.  
  38. #define EXIT_SUCCESS    0
  39. #define EXIT_FAILURE    1
  40.  
  41. #if defined(_HAS_PROTOTYPES) && !defined(_SIZE_T)
  42. #define _SIZE_T
  43. /* size_t is also defined in sys/types.h, stddef.h, and unistd.h. */
  44. typedef    int    size_t;
  45. #endif
  46.  
  47. /*
  48.  *----------------------------
  49.  * String conversion routines:
  50.  *----------------------------
  51.  */
  52.  
  53. _EXTERN double     atof _ARGS_((_CONST char *string));
  54. _EXTERN int     atoi _ARGS_((_CONST char *string));
  55. _EXTERN long int atol _ARGS_((_CONST char *string));
  56. _EXTERN double     strtod _ARGS_((_CONST char *string, char **endPtr));
  57. _EXTERN long int strtol _ARGS_((_CONST char *string, char **endPtr, int base));
  58. _EXTERN unsigned long int
  59.         strtoul _ARGS_((_CONST char *string, char **endPtr, int base));
  60.  
  61. /*
  62.  *------------------
  63.  * Memory allocator:
  64.  *------------------
  65.  */
  66.  
  67. /* 
  68.  * (Many of the "char *"s should be "Address".  See the above comments 
  69.  * about sprite.h.)
  70.  */
  71.  
  72. #ifdef KERNEL
  73.  
  74. _EXTERN Address    malloc _ARGS_((unsigned int bytesNeeded));
  75.  
  76. /*
  77.  * The mips compiler cannot handle some coercions on the left hand side.
  78.  */
  79. #ifndef mips
  80.  
  81. _EXTERN void    _free _ARGS_((Address blockPtr));
  82.  
  83. #ifdef lint
  84. #define        free(ptr) _free(ptr)
  85. #else
  86. #define        free(ptr) {_free(ptr); (ptr) = (Address) NIL; }
  87. #endif /* lint */
  88.  
  89. #else /* mips */
  90.  
  91. _EXTERN int    free _ARGS_((Address blockPtr));
  92.  
  93. #endif /* mips */
  94.  
  95. #else /* KERNEL */
  96.  
  97. _EXTERN _VoidPtr    malloc _ARGS_((unsigned int bytesNeeded));
  98. _EXTERN int    free _ARGS_((_VoidPtr blockPtr));
  99.  
  100. #endif /* KERNEL */
  101.  
  102. _EXTERN _VoidPtr calloc _ARGS_((unsigned int numElems, unsigned int elemSize));
  103. _EXTERN _VoidPtr    realloc _ARGS_((_VoidPtr ptr, unsigned int newSize));
  104. _EXTERN void    Mem_Bin _ARGS_((int numBytes));
  105. _EXTERN char *    Mem_CallerPC();
  106. _EXTERN void    Mem_DumpTrace _ARGS_((int blockSize));
  107. _EXTERN void    Mem_PrintConfig _ARGS_((void));
  108. _EXTERN void    Mem_PrintInUse _ARGS_((void));
  109. _EXTERN void    Mem_PrintStats _ARGS_((void));
  110. _EXTERN void    Mem_PrintStatsInt _ARGS_((void));
  111. /* 
  112.  * The "proc" argument to Mem_SetPrintProc is a varargs function, 
  113.  * so we have delayed declaring the correct prototype for it.
  114.  */
  115. _EXTERN void    Mem_SetPrintProc _ARGS_((void (*proc)(), ClientData data));
  116. _EXTERN int    Mem_Size _ARGS_((Address blockPtr));
  117.  
  118. /*
  119.  * Structure used to set up memory allocation traces.
  120.  */
  121.  
  122. typedef struct {
  123.     int        size;    /* Size of block to trace. */
  124.     int        flags;    /* Flags defined below */
  125. } Mem_TraceInfo;
  126.  
  127. _EXTERN void    Mem_SetTraceSizes _ARGS_((int numSizes,
  128.                       Mem_TraceInfo *arrayPtr));
  129. /*
  130.  * Flags to determine what type of tracing to do.
  131.  *
  132.  *    MEM_PRINT_TRACE        A trace record will be printed each time that
  133.  *                an object of this size is alloc'd or freed.
  134.  *    MEM_STORE_TRACE        The number of blocks in use by each caller
  135.  *                up to a predefined maximum number of callers
  136.  *                is kept in a trace array .
  137.  *    MEM_DONT_USE_ORIG_SIZE    Don't use the original size for tracing, but use
  138.  *                the modified size used by malloc.
  139.  *    MEM_TRACE_NOT_INIT    The trace records stored for MEM_STORE_TRACE
  140.  *                have not been initialized yet.
  141.  */
  142.  
  143. #define    MEM_PRINT_TRACE        0x1
  144. #define    MEM_STORE_TRACE        0x2
  145. #define    MEM_DONT_USE_ORIG_SIZE    0x4
  146. #define    MEM_TRACE_NOT_INIT    0x8
  147.  
  148. extern int    mem_SmallMinNum;
  149. extern int    mem_LargeMinNum;
  150. extern int    mem_LargeMaxSize;
  151.  
  152. /*
  153.  * Statistics counters;  only incremented when tracing is enabled.
  154.  */
  155.  
  156. extern int    mem_NumAllocs;
  157. extern int    mem_NumFrees;
  158.  
  159. /*
  160.  *----------------------------------------------------------------
  161.  * Additional integer math routines, plus structures for returning
  162.  * results from them:
  163.  *----------------------------------------------------------------
  164.  */
  165.  
  166. typedef struct div_t {
  167.     int quot;
  168.     int rem;
  169. } div_t;
  170.  
  171. typedef struct {
  172.     long int quot;
  173.     long int rem;
  174. } ldiv_t;
  175.  
  176. _EXTERN int    abs _ARGS_((int j));
  177. _EXTERN div_t    div _ARGS_((int numer, int denom));
  178. _EXTERN long int labs _ARGS_((long j));
  179. _EXTERN ldiv_t    ldiv _ARGS_((long int numer, long int denom));
  180.  
  181. /*
  182.  *-----------------------------------
  183.  * Miscellaneous additional routines:
  184.  *-----------------------------------
  185.  */
  186.  
  187. _EXTERN void    abort _ARGS_((void));
  188. _EXTERN int    atexit _ARGS_((void (*func)(void)));
  189. _EXTERN _VoidPtr bsearch _ARGS_((_CONST _VoidPtr key, _CONST _VoidPtr base,
  190.         size_t n, size_t size,
  191.     int (*cmp)(_CONST _VoidPtr searchKey, _CONST _VoidPtr tableEntry)));
  192. _EXTERN int    exit _ARGS_((int status));
  193. _EXTERN char *    getenv _ARGS_((char *name));
  194. _EXTERN void    qsort _ARGS_((_VoidPtr base, int n, int size,
  195.       int (*compar)(_CONST _VoidPtr element1, _CONST _VoidPtr element2)));
  196. _EXTERN int    rand _ARGS_((void));
  197. _EXTERN long    random _ARGS_((void));
  198. _EXTERN int    srand _ARGS_((int seed));
  199. _EXTERN int    srandom _ARGS_((int seed));
  200. _EXTERN int    system _ARGS_((_CONST char *command));
  201.  
  202. #endif /* _STDLIB */
  203.